# 注意使用tab键缩进
GO = go
PORT = 8002
BINARY_NAME = main_8002
LDFLAGS = "-s -w"
LOG_FILE = /data/logs/gino.log

## help: Help for this project
help: Makefile
	@echo "Usage:\n  make [command]"
	@echo
	@echo "Available Commands:"
	@sed -n 's/^##//p' $< | column -t -s ':' |  sed -e 's/^/ /'

## build: Compile the linux binary
build:
	@echo "build binary for linux"
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(LDFLAGS) -o $(BINARY_NAME) main.go

## build-local: Compile the binary for local
build-local:
	@echo "build local binary"
	go build -ldflags $(LDFLAGS) -o $(BINARY_NAME) main.go

## run: Build and run
run: build-local
	@./$(BINARY_NAME)

## run-daemon: Build and run in daemon
run-daemon: build-local
	nohup ./$(BINARY_NAME) >> $(LOG_FILE) 2>&1 &

## ps: show the process
ps:
	ps -ef | grep $(BINARY_NAME) | grep -v grep

## start: start the process
start:
	chmod +x $(BINARY_NAME)
	nohup ./$(BINARY_NAME) > /dev/null 2>&1 &

## restart: restart the process
restart:
	chmod +x $(BINARY_NAME)
	kill -USR2 `ps -ef | grep $(BINARY_NAME) | grep -v grep | awk '{print $$2}'`

## stop: stop the process
stop:
	kill `ps -ef | grep $(BINARY_NAME) | grep -v grep | awk '{print $$2}'`

## clean: Clean build files
clean:
	@echo 'clean binary file $(BINARY_NAME)'
	@rm -f $(BINARY_NAME)
